/**
 * @file app\utils\uuid.c
 *
 * Copyright (C) 2023
 *
 * uuid.c is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author HinsShum hinsshum@qq.com
 *
 * @encoding utf-8
 */

/*---------- includes ----------*/
#include "uuid.h"
#include "resources.h"
#include "checksum.h"
#include "options.h"

/*---------- macro ----------*/
#define TAG                                         "UUID"

/*---------- type define ----------*/
/*---------- variable prototype ----------*/
/*---------- function prototype ----------*/
/*---------- variable ----------*/
static uint32_t uuid;

/*---------- function ----------*/
void uuid_init(void)
{
    uint8_t cpu_uuid[12] = {0};
    cpu_get_uuid(cpu_uuid, ARRAY_SIZE(cpu_uuid));
    xlog_tag_info(TAG, "CPU uuid: %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
        cpu_uuid[0], cpu_uuid[1], cpu_uuid[2], cpu_uuid[3],
        cpu_uuid[4], cpu_uuid[5], cpu_uuid[6], cpu_uuid[7],
        cpu_uuid[8], cpu_uuid[9], cpu_uuid[10], cpu_uuid[11]);
    uuid = checksum_crc32_moorgen(cpu_uuid, ARRAY_SIZE(cpu_uuid)) & 0xFFFFFF;

    xlog_tag_info(TAG, "Device Unique ID: %06X\n", uuid);
}

uint32_t uuid_get(void)
{
    return uuid;
}
